package com.ckx.controller;

import com.ckx.domain.ResponseResult;
import com.ckx.domain.dto.RoleAddDto;
import com.ckx.domain.dto.RoleDto;
import com.ckx.domain.dto.RoleUpdateDto;
import com.ckx.domain.entity.Role;
import com.ckx.domain.vo.MenuByRoleAddVo;
import com.ckx.domain.vo.PageVo;
import com.ckx.domain.vo.RoleVo;
import com.ckx.service.MenuService;
import com.ckx.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @GetMapping("/list")
    public ResponseResult list(Integer pageNum, Integer pageSize, Role role){
        PageVo pageVo = roleService.selectByPage(pageNum, pageSize, role);
        return ResponseResult.okResult(pageVo);
    }

    @PostMapping
    public ResponseResult addRole(@RequestBody RoleAddDto roleAddDto){
        roleService.addRole(roleAddDto);
        return ResponseResult.okResult();
    }

    @PutMapping("/changeStatus")
    public ResponseResult changeStatus(@RequestBody RoleDto roleDto){
        roleService.changeStatus(roleDto);
        return ResponseResult.okResult();
    }

    @GetMapping("/{id}")
    public ResponseResult getRoleInfo(@PathVariable Long id){
        Role role = roleService.getRoleInfo(id);
        return ResponseResult.okResult(role);
    }

    @PutMapping
    public ResponseResult updateRole(@RequestBody RoleUpdateDto roleUpdateDto){
        roleService.updateRole(roleUpdateDto);
        return ResponseResult.okResult();
    }

    @DeleteMapping("/{id}")
    public ResponseResult delRole(@PathVariable Long id){
        roleService.del4DelFlag(id);
        return ResponseResult.okResult();
    }

    @GetMapping("/listAllRole")
    public ResponseResult listAllRole(){
        List<RoleVo> roleVos = roleService.listAllRole();
        return ResponseResult.okResult(roleVos);
    }

}
